package ms.unicorn.util;

import java.util.Map;
import java.util.TreeMap;

public class TypeConvert {
	static final Map<String, Integer> figureMap = new TreeMap<String, Integer>();
	
	static {
		figureMap.put("diamond", FigureConstant.FIGURE_TYPE_DIAMOND);
		figureMap.put("circle", FigureConstant.FIGURE_TYPE_CIRLCE);
		figureMap.put("default", FigureConstant.FIGURE_TYPE_DEFAULT);
	}
	
	public static int toInt(String value, int defValue) {
		try {
			return Integer.parseInt(value);
		}
		catch(Exception e) {
			return defValue;
		}
	}
	
	public static boolean toBool(String value) {
		return "true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value);
	}
	
	public static int toFigureConstant(String figureName) {
		return figureMap.get(figureName);
	}
}
